import java.util.Stack;

public class test {
    public static int calPoints(String[] operations) {
        Stack<Integer> stack=new Stack<>();
        int op1;
        int op2;
        for(String x:operations){
            switch(x){
                case "+":
                    op1=stack.pop();
                    op2=stack.pop();
                    stack.push(op2);
                    stack.push(op1);
                    stack.push(op1+op2);
                    break;
                case "C":
                    stack.pop();
                    break;
                case "D":
                    op1=stack.peek();
                    stack.push(2*op1);
                    break;
                default:
                    stack.push(Integer.valueOf(x));
                    break;
            }
        }
        int sum=0;
        while(!stack.isEmpty()){
            sum+=stack.pop();
        }
        return sum;
    }

    public static void main(String[] args) {
        String[] operations=new String[]{"5","-2","4","C","D","9","+","+"};
        System.out.println(calPoints(operations));
    }
}
